home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 6.5 KB | 221 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Object Oriented Shell
- *
- * Events.C
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This file contains the code to interfrace directly to your WindowObj.
- * This will perform certain rudimentary functions for windows in general,
- * all window specific functionality will be handled by your Obj or by WindowObj.
- *
- *************************************************************************************/
-
- #include "main.h"
- #include <Traps.h>
- #include "WindowObj.h"
- #include <Strings.h>
-
-
- /**************************************************************************************
-
- CloseAnyWindow
-
- Close the given window in a manner appropriate for that window. If the
- window belongs to a DA, we call CloseDeskAcc. For dialogs, we simply hide
- the window. If we had any document windows, we would probably call either
- DisposeWindow or CloseWindow after disposing of any docuemtn data and/or
- controls.
-
- ***************************************************************************************/
- Boolean CloseAnyWindow(WindowPtr window)
- {
- if( IsDAWindow(window))
- {
- CloseDeskAcc( ( (WindowPeek) window)->windowKind);
- return true;
- }
- else if(IsDialogWindow(window))
- {
- HideWindow(window);
- return true;
- }
- else if(IsAppWindow(window))
- {
- if(window == ToWindowObj(window)->me)
- {
- return (ToWindowObj(window)->CloseWindowObj());
- }
- else
- {
- DisposeWindow( window);
- return true;
- }
- }
- else // Wasn't any of the above windows...
- return false; // I couldn't close it...
- }
-
-
- /**************************************************************************************
-
- CloseAllAppWindows
-
- This routine will close all application windows. Its function is mostly for
- object windows which need to close all the application windows.
- It's also used by the quit code.
-
- ***************************************************************************************/
- Boolean CloseAllAppWindows( void)
- {
- WindowPtr window;
- Boolean closeFlag = false;
-
- while( (window = FrontWindow()) != nil)
- closeFlag &= CloseAnyWindow( window);
- return closeFlag;
- }
-
- /**************************************************************************************
-
- AppConvertScrap
-
- This code converts scraps to the DeskScrap.
- The catch is that there isn't anything the standard application can do.
- The reason is that there is no TextEditRecord and there are no open windows.
- Hopefully windows are cogniscent enough to handle their data correctly.
-
- ***************************************************************************************/
- void AppConvertScrap()
- {
- // I do nothing. I suggest you do nothing.
- // But, obviously the hook has been installed.
- }
-
- /**************************************************************************************
-
- DeathAlertStr
-
- Display an alert that tells the user an error occurred, then exits the
- program. This routine is used as an ultimate bail-out for serious errors
- that bprohibit the continuation of the application. The error string is
- used so that a relevant message can be displayed.
-
- ***************************************************************************************/
- void DeathAlertStr(char *string)
- {
- short itemHit;
- Str255 theMessage;
-
- SetCursor( &qd.arrow);
- c2pstr( string);
- ParamText(theMessage, NIL, NIL, NIL);
- SetCursor( &qd.arrow);
- itemHit = StopAlert(rErrorAlert, NIL);
- ExitToShell();
- }
-
-
- /**************************************************************************************
-
- DeathAlertStrErr
-
- Display an alert that tells the user an error occurred and report the error.
- Then exits the program. This routine is used as an ultimate bail-out for
- serious errors that bprohibit the continuation of the application.
- The error string is used so that a relevant message can be displayed.
-
- ***************************************************************************************/
- void DeathAlertStrErr(char *string, OSErr errorCode)
- {
- short itemHit;
- Str255 theMessage;
- Str255 errString;
-
- SetCursor( &qd.arrow);
- c2pstr( string);
- NumToString( errorCode, errString);
- ParamText(theMessage, errString, NIL, NIL);
- SetCursor( &qd.arrow);
- itemHit = StopAlert(rErrorAlert, NIL);
- ExitToShell();
- }
-
-
- /**************************************************************************************
-
- IsAppWindow
-
- Check to see if a window belongs to the application. If the window pointer
- passed was NIL, then it could not be an application window. WindowKinds
- that are negative belong to the sytem and wndowKinds less than userKind
- are reserved by Apple except for windowKinds equal to dialogKind, which
- mean it is a dialog.
-
- ***************************************************************************************/
- Boolean IsAppWindow(WindowPtr window)
- {
- if(window == NIL)
- return false;
- else
- return ((WindowPeek)window)->windowKind == WindowObjKind;
- }
-
- /**************************************************************************************
-
- IsDAWindow
-
- Check to see if a window belongs to a desk accessory. It belongs to a DA
- if the windowKind field of the widnow record is negative.
-
- ***************************************************************************************/
- Boolean IsDAWindow(WindowPtr window)
- {
- if( window == NIL)
- return false;
- else
- return ( ( (WindowPeek)window)->windowKind < 0);
- }
-
- /**************************************************************************************
-
- IsDialogWindow
-
- Check to see if a window belongs is a dialog window. We can determine this by
- checking to see if the windowKind field is equal to dialogKind.
-
- ***************************************************************************************/
- Boolean IsDialogWindow(WindowPtr window)
- {
- if( window == NIL)
- return false;
- else
- return( ( (WindowPeek)window)->windowKind == dialogKind);
- }
-
- /**************************************************************************************
-
- InvalidateScrollbars
-
- Call InvalRect on the right and bottom edges of a window. This routine is
- called during the resizing of a window to take care of the scroll bar lines
- and grow icon.
-
- ***************************************************************************************/
- void InvalidateScrollbars(WindowPtr theWindow)
- {
- Rect tempRect;
-
- SetPort( theWindow);
- tempRect = theWindow->portRect;
- tempRect.left = tempRect.right - 15;
- InvalRect(&tempRect);
- EraseRect(&tempRect);
- tempRect = theWindow->portRect;
- tempRect.top = tempRect.bottom - 15;
- InvalRect( &tempRect);
- EraseRect( &tempRect);
- }
-